package com.yc.thread.lock;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 验证：CountDownLatch的用法
 * CountDownLatch就是个计数器，和在不在线程中无关
 * @author yuancan
 *
 */
public class CountDownLatchTest2 {
	
	public void m1() {
		
	}

	public static void main(String[] args) {
		try {
			final CountDownLatch latch = new CountDownLatch(2);
			
			System.out.println(latch.getCount());//2
			
			latch.countDown();
			Thread.sleep(1000);
			System.out.println(latch.getCount());//1
			latch.countDown();
			System.out.println(latch.getCount());//0
			Thread.sleep(1000);
			
			latch.countDown();
			System.out.println(latch.getCount());//再减还是0
			
			latch.await();
			System.out.println("-------------");
		} catch (InterruptedException e) {
			
		}
		
	}
}
